package cn.cs.service.impl;

import cn.cs.client.WxAccessClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.config.WXPayConfig;
import cn.cs.mapper.WxAccessTokenMapper;
import cn.cs.pojo.WxAccessToken;
import cn.cs.service.WxAccessTokenService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class WxAccessTokenServiceImpl implements WxAccessTokenService {

    @Resource
    private WxAccessClient wxAccessClient;

    public WxAccessToken getWxAccessTokenById(String id){
        return wxAccessClient.getWxAccessTokenById(id);
    }

    public List<WxAccessToken> getWxAccessTokenListByMap(Map<String, Object> param) throws Exception {
        return wxAccessClient.getWxAccessTokenListByMap(param);
    }

    public Integer getWxAccessTokenCountByMap(Map<String, Object> param) throws Exception {
        return wxAccessClient.getWxAccessTokenCountByMap(param);
    }

    public Integer addWxAccessToken(WxAccessToken wxAccessToken) throws Exception {
        return wxAccessClient.addWxAccessToken(wxAccessToken);
    }

    public Integer modifyWxAccessToken(WxAccessToken wxAccessToken) throws Exception {
        return wxAccessClient.modifyWxAccessToken(wxAccessToken);
    }

    public Integer deleteWxAccessTokenById(Long id) throws Exception {
        return wxAccessClient.deleteWxAccessTokenById(id);
    }

    public Page<WxAccessToken> queryWxAccessTokenPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = wxAccessClient.getWxAccessTokenCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<WxAccessToken> wxAccessTokenList = wxAccessClient.getWxAccessTokenListByMap(param);
        page.setRows(wxAccessTokenList);
        return page;
    }

}
